package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MsgConfiguration;
import com.ruoyi.system.service.IMsgConfigurationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息配置Controller
 *
 * @author ruoyi
 * @date 2024-04-01
 */
@RestController
@RequestMapping("/system/info/configuration")
public class MsgConfigurationController extends BaseController
{
    @Autowired
    private IMsgConfigurationService msgConfigurationService;

    /**
     * 查询消息配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody MsgConfiguration msgConfiguration)
    {
        setStartPage(msgConfiguration.getPageNum(),msgConfiguration.getPageSize());
        List<MsgConfiguration> list = msgConfigurationService.selectMsgConfigurationList(msgConfiguration);
        return getDataTable(list);
    }

    /**
     * 查询消息配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:list')")
    @GetMapping("/Msglist")
    public TableDataInfo Msglist(MsgConfiguration msgConfiguration)
    {
        List<MsgConfiguration> list = msgConfigurationService.selectMsgConfigurationList(msgConfiguration);
        return getDataTable(list);
    }


    /**
     * 获取消息配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(msgConfigurationService.selectMsgConfigurationById(id));
    }

    /**
     * 新增消息配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:add')")
    @Log(title = "消息配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MsgConfiguration msgConfiguration)
    {
        return toAjax(msgConfigurationService.insertMsgConfiguration(msgConfiguration));
    }

    /**
     * 修改消息配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:edit')")
    @Log(title = "消息配置", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody MsgConfiguration msgConfiguration)
    {
        return toAjax(msgConfigurationService.updateMsgConfiguration(msgConfiguration));
    }

    /**
     * 修改消息配置状态
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:edit')")
    @Log(title = "消息配置", businessType = BusinessType.UPDATE)
    @PutMapping("/editStatus")
    public AjaxResult editStatus(@RequestBody MsgConfiguration msgConfiguration)
    {
        return toAjax(msgConfigurationService.updateMsgConfiguration(msgConfiguration));
    }

    /**
     * 删除消息配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:remove')")
    @Log(title = "消息配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(msgConfigurationService.deleteMsgConfigurationById(id));
    }
}
